﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FastDATA;

namespace CursoUNICEUB
{
    public partial class Novidades : System.Web.UI.Page
    {
        protected int ultimoTamanho;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.hylInserirNovidade.Visible = Session["aluno"] != null;
                carregaNoticias();
            }
        }

        private void carregaNoticias()
        {
            try
            {
                using (DCCursoDataContext banco = new DCCursoDataContext())
                {
                    var q = from e in banco.DENovidades
                            where e.Ativo orderby e.Data descending
                            select e;

                    this.rptNoticias.DataSource = q.ToList();
                    this.rptNoticias.DataBind();
                }
            }
            catch (Exception)
            {
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "error", "alert('Houve um erro no momento de carregar as notícias.');", true);
            }
        }
    }
}